/********************************************************************************
 * ItemWantedAction.java
 *
 * Created by Jigar Mistry
 * Last modified Date: Dec 10, 2008 11:52:29 AM by Jigar Mistry
 * Version : 0.1
 * Copyright (c) 2008 - 2009 cyberThink Infotech Pvt. Ltd., All rights reserved.
 ********************************************************************************/
package com.printeverywhere.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.printeverywhere.delegator.CommonFunctionDelegator;
import com.printeverywhere.dto.GeneralCategories;
import com.printeverywhere.util.SearchCriteria;

public class ItemWantedAction extends FrontBaseSupport implements ServletRequestAware {

	/**  */
	private static final long serialVersionUID = 1L;

	private HttpServletRequest request;

	private String subCategory;

	private List<GeneralCategories> listGeneralCategories = new ArrayList<GeneralCategories>();

	public ItemWantedAction() {
		super(true, false);
		setCategoryDisplay(true);
	}

	public String execute() {
		if(request.getSession().getAttribute("categoryInSession") != null) {
			SearchCriteria searchCriteria = new SearchCriteria();
			searchCriteria.setAttribute("generalCategories.categoryId", Integer.parseInt(request.getSession().getAttribute("categoryInSession").toString()));
			List<GeneralCategories> tmpGeneralCategories = (List<GeneralCategories>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, GeneralCategories.class);

			boolean flag = false;
			for (GeneralCategories generalCategories : tmpGeneralCategories) {

				if(flag) {
					searchCriteria.removeAllAttribute();
					searchCriteria.setAttribute("generalCategories.categoryId", generalCategories.getCategoryId());
					generalCategories.setGeneralCategoriesList((List<GeneralCategories>) CommonFunctionDelegator.getObjectBySearchCriteria(searchCriteria, GeneralCategories.class));
					this.listGeneralCategories.add(generalCategories);
				} else {
					this.subCategory = generalCategories.getCategoryName();
					flag = true;
				}
			}
		}
		return SUCCESS;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public String getSubCategory() {
		return subCategory;
	}

	public void setSubCategory(String subCategory) {
		this.subCategory = subCategory;
	}

	public List<GeneralCategories> getListGeneralCategories() {
		return listGeneralCategories;
	}
}
